#include <iostream>

using namespace std;
/*
    int arr[10] = {1, 3, 5, 1, 3, 5, 1, 3, 5, 1};
要求
    找出元素 1 在数组中出现的所有下标位置
    {0, 3, 6, 9};
*/

int a = 0;
int temp = 10;

//校验
void wrong(int arr[], int capacity);

//决定数组的大小
int number(int arr[], int capacity);

//生成新数组
void subscript_function(int arr[], int capacity, int new_subscalar_array[]);

//输出新数组
void output_function(int new_subscalar_array[], int size);


int main(int argc, char const *argv[])
{
    int arr[10] = {1, 3, 5, 1, 3, 5, 1, 3, 5, 1};
    
    wrong(arr,10);
    a = number(arr, 10);

    int new_subscalar_array[a] = {0};
    subscript_function(arr, 10, new_subscalar_array);
    output_function(new_subscalar_array, a);

    return 0;
}

void wrong(int arr[], int capacity)
{
    int worringa = -1;
    for(int i = 0; i < capacity; i++)
    {
        if(arr[i] == temp)
        {
            worringa = 1;
        }
    }
    if(worringa < 0 )
    {
         cout << "有问题！！！！！" << endl;
          throw new out_of_range("用户提供的下标位置超出有效范围！");
    }
   
}
int number(int arr[], int capacity)
{
    int count = 0;
    for(int i = 0; i < capacity; i++)
    {
        if(arr[i] == temp)
        {
            count++;
        }
    }
    return count;
}
void subscript_function(int arr[], int capacity, int new_subscalar_array[])
{
    int index = 0;
    for(int i = 0; i < capacity; i++)
    {
        if(arr[i] == temp)
        {
            new_subscalar_array[index++] = i;
        }
    }
    
}
void output_function(int new_subscalar_array[], int size)
{
    for(int i = 0; i < size; i++)
    {
        cout << new_subscalar_array[i] << "  ";
    }   
   
}